<template>
	<view class="item-main">
<!-- 		<view class="item-top">
			<span class='left'>{{ item.title }}</span>
			<template v-if="item.isReward==2">
				<span class='right' @click="publish " style="margin-right: 3px;">发布悬赏</span>
			</template>
			<template v-else>
				<span class='right' @click="publish" style="margin-right: 3px;">修改悬赏</span>
				<template v-if="item.rewardStatus == 1">
					<span class='right' @click="setReward(0)" style="margin-right: 3px;">打开悬赏</span>
					<span class='right' v-if="item.trusteeship !='1'" @click="deleteReward"
						style="margin-right: 3px;">删除悬赏</span>
				</template>
				<template v-else>
					<span class='right' @click="setReward(1)" style="margin-right: 3px;">关闭悬赏</span>
				</template>
			</template>
			<span class='right rt' @click="tgMeth(item.rewardId)"
				v-if="item.isReward == '1' &&item.trusteeship !='1'">立即托管</span>
		</view> -->
		<!-- 		<view class="item-center" v-if="item.demandStatus == 0" @click="toPage('/pages/details/supplyChain/supplyChain?mind=1&id='+item.id)" >
			<view class="acea-row">
				<img class='item-img' :src="item.imaegs" alt="">
				<view class="content-main">
					<p>名称：{{ item.commodityName}}</p>
					<p>价格：{{ item.commodityPrice || 0 }}元</p>
					<p>服务区域：{{ item.serviceArea || '' }}</p>
					<p>服务特色：{{ item.serviceCharacteristics?item.serviceCharacteristics:'无'  }}</p>
				</view>
			</view>
			<span>{{ item.mangStatus == 0 ? '待审核' : ( item.mangStatus == 1 ? '通过' : '驳回') }}</span>
		</view> -->
		<rewaredComp :item="item" :rewardType="item.demandStatus == 1?9:6" @tgMeth="tgMeth" @updateItem ="(k,v)=>$emit('updateItem', k, v)" />
		<view class="item-center" v-if="item.demandStatus == 1"
			@click="toPage('/pages/details/askSupply/askSupply?mind=1&id='+item.id)">
			<view class="acea-row" style="flex-wrap: nowrap;">
				<view class="content-main">
					<p>名称：{{ item.commodityName}}</p>
					<p>价格：{{ item.smallPrice + (item.bigPrice?'-'+item.bigPrice:'') }}元</p>
					<p>期望区域：{{ item.serviceAreaName || '' }}</p>
					<p>服务特色：{{ item.serviceCharacteristics?item.serviceCharacteristics:''  }}</p>
				</view>
			</view>
			<!-- <span>{{ item.mangStatus == 0 ? '待审核' : ( item.mangStatus == 1 ? '通过' : '驳回') }}</span> -->
		</view>
		<view class="item-center" v-else @click="toPage('/pages/details/supplyChain/supplyChain?mind=1&id='+item.id)">
			<view class="acea-row" style="flex-wrap: nowrap;">
				<img class='item-img' :src="item.imaegs" alt="">
				<view class="content-main">
					<p>名称：{{ item.commodityName}}</p>
					<p>价格：{{ item.commodityPrice || 0 }}元</p>
					<p>服务区域：{{ item.serviceAreaName || '' }}</p>
					<p>服务特色：{{ item.serviceCharacteristics?item.serviceCharacteristics:'无'  }}</p>
				</view>
			</view>
			<!-- <span>{{ item.mangStatus == 0 ? '待审核' : ( item.mangStatus == 1 ? '通过' : '驳回') }}</span> -->
		</view>

		<view class="item-bottom">
			<p>已为您匹配到{{item.matchingNum?item.matchingNum:0}}人·浏览 {{item.view?item.view:0}} ·咨询
				{{item.communication?item.communication:0}}
			</p>
			<view class="bottom-btn">
				<span
					@click="$emit('to-topping',item.id,item.demandStatus == 1?'supplyBeg':'supply')">{{item.sort == '1'?'已置顶':'置顶'}}</span>
				<span>群发</span>
				<span @click="$emit('toVip',item)" :class="item.isVip== 1?'vip':''">
					{{item.isVip == '1'?'VIP信息':'VIP'}}</span>
				<span @click="$emit('visitor',item)">访客</span>
				<span @click="jumpPage">编辑</span>
				<span @click="$emit('setMeth',item)">设置</span>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		toPage
	} from '@/filters/commFilter.js'
	import {
		closeReward,
		deleteReward,
		reardTrusteeship
	} from '@/api/api.js'
	import rewaredComp from './publishReward/index.vue'
	export default {
		components: {
			rewaredComp
		},
		props: ['item'],
		data() {
			return {

			}
		},

		mounted() {
			console.log("$noImageShow", this.item)
		},
		methods: {
			toPage,
			publish() {
				this.item.type = this.item.demandStatus == 1 ? 9 : 6;
				console.log("this.item.type", this.item.type)
				let item = JSON.stringify(this.item);
				uni.navigateTo({
					url: '/pages/releases/offeraRreward/offeraRreward?item=' + item
				})
			},
			jumpPage() {
				toPage('/pages/releases/supplyChain/supplyChain?type=' + (this.item.demandStatus == 1 ? this.item
					.demandStatus : 0) + '&id=' + this.item.id)
			},
			setReward(st){
							let that = this;
							uni.showModal({
								title: '提示',
								content: '是否'+(st==1?'关闭':'打开')+'当前悬赏',
								success: function (res) {
									if (res.confirm) {
										closeReward({
											id: that.item.rewardId,
											status: st
										}).then(res=>{
											// that.item. 'rewardStatus' = st;
											that.$emit("updateItem",'rewardStatus',st)
											that.$util.Tips({
												title: (st==1?'关闭':'打开')+'悬赏成功'
											})
											// that.item.rewardStatus = st;
										})
									} else if (res.cancel) {
										// console.log('用户点击取消');
									}
								}
							});
							
						},
						deleteReward(){
							let that = this;
							uni.showModal({
								title: '提示',
								content: '是否删除当前悬赏',
								success: function (res) {
									if (res.confirm) {
										console.log("that.item.rewardId",that.item.rewardId)
										deleteReward(that.item.rewardId).then(res=>{
											// that.item. 'rewardStatus' = st;
											that.$emit("updateItem",'isReward',2)
											that.$util.Tips({
												title: '删除悬赏成功'
											})
											// that.item.rewardStatus = st;
										})
									} else if (res.cancel) {
										// console.log('用户点击取消');
									}
								}
							});
						},
			//托管方法
			tgMeth(id) {
				let that = this;
				console.log(id)
				uni.showModal({
					title: "提示",
					content: "是否立即托管",
					success(res) {
						if (res.confirm) {
							reardTrusteeship({
								id
							}).then(res => {
								if (res.code == 200) {
									that.$util.Tips({
										title: '托管成功'
									})
									setTimeout(() => {
										that.page = 1;
										that.initList();
									}, 1500)

								}
							}).catch(e => {
								that.$util.Tips({
									title: e
								}, {
									tab: 2,
									url: "/pages/users/user_money/index"
								})
							})
						}
					}

				})

			},
		}
	}
</script>

<style lang="scss">
	.item-main {
		padding-bottom: 36rpx;
		background-color: #ffffff;
		margin: 40rpx 28rpx;
		border-radius: 20rpx;
		padding: 0rpx 24rpx 0rpx 28rpx;

		.item-top {
			// margin: 0rpx 24rpx 0rpx 28rpx;
			border-bottom: 2rpx solid rgba(238, 238, 238, 1);
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 86rpx;

			.left {
				font-size: 30rpx;
				font-weight: 400;
				width: 75%;
				color: rgba(56, 56, 56, 1);
			}

			.right {
				border-radius: 10rpx;
				background-color: rgb(238, 33, 45);
				color: rgba(255, 255, 255, 1);
				font-size: 24rpx;
				width: 20%;
				height: 44rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.item-center {
			display: flex;
			justify-content: space-between;
			margin-top: 36rpx;
			padding-bottom: 40rpx;
			border-bottom: 2rpx solid rgba(238, 238, 238, 1);

			.acea-row {
				display: flex;
				align-items: center;

				.item-img {
					width: 170rpx;
					height: 144rpx;
					border-radius: 10rpx;
					margin-right: 18rpx;
				}

				.content-main {
					font-size: 24rpx;
					font-weight: 400;
					line-height: 20px;
					color: rgba(128, 128, 128, 1);

					p {
						margin: 0;
						padding: 0;
					}
				}
			}

			span {
				font-size: 22rpx;
				font-weight: 400;
				color: rgba(238, 33, 45, 1);
			}
		}

		.item-bottom {
			p {
				margin-top: 20rpx;
				font-size: 22rpx;
				font-weight: 400;
				line-height: 40rpx;
				color: rgba(166, 166, 166, 1);
			}

			.bottom-btn {
				padding-bottom: 36rpx;
				margin-top: 18rpx;
				display: flex;
				justify-content: space-between;

				span {
					font-size: 24rpx;
					color: rgba(128, 128, 128, 1);
					width: 90rpx;
					line-height: 44rpx;
					border-radius: 4rpx;
					border: 2rpx solid rgba(229, 229, 229, 1);
					display: flex;
					justify-content: center;
				}
			}
		}
	}

	.v {
		// display: flex;
		margin-left: 10rpx;
		padding: 1rpx 10rpx;
	}

	.vip {
		border: 1px solid red !important;
		color: red !important;
	}
</style>